package job1.server;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

//使用德鲁伊连接池
public class DruidDataConnPool {
    //    1.连接池对象
    private DataSource dataSource;

//    根据properties配置参数连接数据源
    public DruidDataConnPool(Properties properties) throws Exception {
        dataSource = DruidDataSourceFactory.createDataSource(properties);
    }

    // 从链接池获取链接
    public Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }
//   获取连接池
    public DataSource getDataSource() {
        return dataSource;
    }

    // 释放资源
    public static void close(AutoCloseable... closeables) throws Exception {
        for (AutoCloseable closeable : closeables)
            if (closeable != null)
                closeable.close();
    }

//    无需任何代码
    public void destroy() {
    }
}
